package hn.sigit.model.hnd.ladmshadow;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;


@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="PartyMember", schema="ladmshadow")
@Inheritance(strategy=InheritanceType.JOINED)
@IdClass(PartyMemberPK.class)
public class PartyMember extends AssociationInfo implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private long partyId;
	private long grouppartyId;
	private GroupParty groupparty;
	private Party party;
	private hn.sigit.model.ladm.special.Rational share;

	public PartyMember() {
	}

	
	@Id
	@Column(name="PartyID", nullable=false)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="shw_partymember_id_gen")
	@SequenceGenerator(name="shw_partymember_id_gen", sequenceName="shw_partymember_id_seq", allocationSize=1)
	public long getpartyId() {
		return partyId;
	}
	protected void setpartyId(long value) {
		this.partyId = value;
	}
	
	@Id
	@Column(name="GroupPartyPartyID", nullable=false)
	@GeneratedValue(generator="VC0A8016712F23FC47F700F1D")
	@org.hibernate.annotations.GenericGenerator(name="VC0A8016712F23FC47F700F1D", strategy="foreign", parameters=@org.hibernate.annotations.Parameter(name="property", value="Id"))
	public long getgrouppartyId() {
		return grouppartyId;
	}
	protected void setgrouppartyId(long value) {
		this.grouppartyId = value;
	}
	
	@Type(type = "hn.sigit.model.ladm.special.RationalUserType")
	@Columns(columns = {
			@Column(name = "share_numerator"),
			@Column(name = "share_denominator")
	})
	public hn.sigit.model.ladm.special.Rational getShare() {
		return share;
	}
	public void setShare(hn.sigit.model.ladm.special.Rational value) {
		this.share = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=GroupParty.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="GroupPartyPartyID", referencedColumnName="PartyID") })
	public GroupParty getgroupparty() {
		return groupparty;
	}
	public void setgroupparty(GroupParty value) {
		this.groupparty = value;
	}
	
	@PrimaryKeyJoinColumn
	@ManyToOne(targetEntity=Party.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="PartyID", referencedColumnName="ID") })
	public Party getparty() {
		return party;
	}
	public void setparty(Party value) {
		this.party = value;
	}
	

	
	public boolean equals(Object aObj) {
		if (aObj == this)
			return true;
		if (!(aObj instanceof PartyMember))
			return false;
		PartyMember partymember = (PartyMember)aObj;
		if (getparty() == null) {
			if (partymember.getparty() != null)
				return false;
		}
		else if (!getparty().equals(partymember.getparty()))
			return false;
		if (getgroupparty() == null) {
			if (partymember.getgroupparty() != null)
				return false;
		}
		else if (!getgroupparty().equals(partymember.getgroupparty()))
			return false;
		return true;
	}
	
	public int hashCode() {
		int hashcode = 0;
		if (getparty() != null) {
			hashcode = hashcode + (int) getparty().getORMID();
		}
		if (getgroupparty() != null) {
			hashcode = hashcode + (int) getgroupparty().getORMID();
		}
		return hashcode;
	}
	
	
	public String toString() {
		return super.toString();
	}
	
	private boolean _saved = false;
	
	public void onSave() {
		_saved=true;
	}
	
	
	public void onLoad() {
		_saved=true;
	}
	
	
	@Transient
	public boolean isSaved() {
		return _saved;
	}
	
	
}
